<?
	require_once "../../_func/__Global.php";
	require_once "../../_func/__Local.php";
	require_once "../../_func/__MysqlFunc.php";
	require_once "../../_func/_CodeFunc.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>출하등록하기</title>
<link href="../css/layout.css" type="text/css" rel="stylesheet" />
<link type="text/css" href="/css/hot-sneaks/jquery-ui-1.8.18.custom.css" rel="stylesheet" />	
<script type="text/javascript" src="/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="/js/jquery-ui-1.8.18.custom.min.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript">
$(function(){
	// Datepicker
	$('#trade_date').datepicker({
		inline: true,
		showOn: 'button',
		buttonImage:"/img/ico_cal.jpg",
		buttonImageOnly: true
	});
	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);

	$('#trade_arrivaldate').datepicker({
		inline: true,
		showOn: 'button',
		buttonImage:"/img/ico_cal.jpg",
		buttonImageOnly: true
	});
});
</script>
<script type="text/javascript">
	function fnallcheck()
	{
		if ($('#all').is(':checked'))
		{
			$('input:checkbox[name="tseq[]"]').each(function(){
				this.checked=true;
			});
		}
		else
		{
			$('input:checkbox[name="tseq[]"]').each(function(){
				this.checked=false;
			});
		}
	}

	function input_check()
	{
		var orderTotal = Number($('#pototal').val());
		var tradeNumber = 0;

		var chkobj = document.getElementsByName("tseq");
		var tobj = document.getElementsByName("tradenum");
		var pobj = document.getElementsByName("pnumber");

		for (var i=0;i<chkobj.length;i++)
		{
			if (chkobj[i].checked)
			{
				if (tobj[i].value=="")
				{
					alert("출하량을 입력하세요");
					tobj[i].focus();
					return;
				}
				if (!checkNumber(tobj[i].value))
				{
					alert("출하량은 숫자만 입력하세요");
					tobj[i].value="";
					tobj[i].focus();
					return;
				}
				if (Number(pobj[i].value)<Number(tobj[i].value))
				{
					alert("재고량 보다 출하량이 많습니다\n다시 입력하세요");
					tobj[i].value="";
					tobj[i].focus();
					return;
				}
				tradeNumber += Number(tobj[i].value);
			}
		}
		if (orderTotal!=tradeNumber)
		{
			alert("총중량이 맞지않습니다.\n다시 입력하세요.");
			return;
		}
		if ($('#trade_date').val()=="")
		{
			alert("출하일을 입력하세요");
			$('#trade_date').focus();
			return;
		}
		if ($('#trade_price').val()=="")
		{
			alert("단가를 입력하세요");
			$('#trade_price').focus();
			return;
		}
		if (!isNumber($('#trade_price')))
		{
			alert("단가는 숫자만 입력하세요");
			$('#trade_price').val("");
			$('#trade_price').focus();
			return;
		}
		if ($('#trade_arrivaldate').val()=="")
		{
			alert("도착일을 입력하세요");
			$('#trade_arrivaldate').focus();
			return;
		}
		if ($('#trade_arrivaltime').val()=="")
		{
			alert("도착시간을 선택하세요");
			$('#trade_arrivaltime').focus();
			return;
		}
		document.theForm.mode.value="w";
		document.theForm.target="if_nvl";
		document.theForm.submit();
	}
	function fnclose()
	{
		opener.location.reload(); 
		this.window.close();
	}
</script>
</head>
<body class="pop">
<!-- view start -->
<? include("./item_manage_out_write_view.php"); ?>
<!-- view end -->
<div class="manage_outtitle"><span>출하등록하기</span></div>
	<div class="memoplace">
			<div class="tableTitle"><span class="b"></span>수발주내역</div>
				<table cellpadding="0" cellspacing="1" border="0" class="erpTable">
					<tr>
						<th>수발주번호</th>
						<td><?=$ocode?></td>
						<th>출하처</th>
						<td><?=$odestname?></td>
						<th>거래방법</th>
						<td><?=$odername?></td>
						<th>중량</th>
						<td><span class="weight"><?=$ototal?>kg</span></td>
					</tr>
				</table>	
			<div class="tableTitle"><span class="b"></span>선별재고리스트</div>
			<form name="theForm" method="post" action="./item_manage_out_write_proc.php">
			<input type="hidden" name="mode" id="mode" />
			<input type="hidden" name="seq" id="seq" value="<?=$seq?>" />
			<input type="hidden" name="pototal" id="pototal" value="<?=$ototal?>" />
			<input type="hidden" name="order_code" id="order_code" value="<?=$ocode?>" />
				<table cellpadding="0" cellspacing="1" border="0" class="erpTable">
				<colgroup>
				<col width="3%" />
				</colgroup>
					<tr>	
						<th><input type="checkbox" id="all" name="all" title="리스트 전체 삭제" onclick="fnallcheck()" /></th>
						<th>농협명</th>
						<th>품목</th>
						<th>품종</th>
						<th>등급</th>
						<th>규격</th>
						<th>중량</th>
						<th>재고량</th>
						<th>출하량</th>
					</tr>
<!-- list start -->
<? include("./item_manage_out_write_list.php"); ?>
<!-- list end -->
				</table>
				<div class="tableTitle"><span class="b"></span>출하사항 입력</div>
            <table cellpadding="0" cellspacing="1" border="0" class="erpTable">
            	<tr>
                    <th>출하일시</th>
					<th>단가</th>
					<th>도착일</th>
					<th>도착시간</th>					 
				</tr>
				<tr>
					<td>
						<input type="text" id="trade_date" value="<?=date('Y-m-d')?>" name="trade_date" title="출하일입력/달력을클릭해주세요." readonly class="boxinput w65" style="margin-right:2px;vertical-align:top;" />
					</td>
					<td><input type="text" id="trade_price" name="trade_price" title="단가" class="boxinput w65"/></td></td>
					<td>
						<input type="text" id="trade_arrivaldate" value="<?=date('Y-m-d')?>" name="trade_arrivaldate" title="도착일시입력/달력을클릭해주세요." readonly class="boxinput w65" style="margin-right:2px;vertical-align:top;" />
					</td>
					<td>
						<select name="trade_arrivaltime" id="trade_arrivaltime">
                        	<option value="">선택</option>
                            <option value="24">24시</option>
                            <option value="23">23시</option>
                            <option value="22">22시</option>
                            <option value="21">21시</option>
                            <option value="20">20시</option>
                            <option value="19">19시</option>
                            <option value="18">18시</option>
                            <option value="17">17시</option>
                            <option value="16">16시</option>
                            <option value="15">15시</option>
                            <option value="14">14시</option>
                            <option value="13">13시</option>
                            <option value="12">12시</option>
                            <option value="11">11시</option>
                            <option value="10">10시</option>
							<option value="09">9시</option>
							<option value="08">8시</option>
							<option value="07">7시</option>
							<option value="06">6시</option>
						</select>
					</td>
				</tr>
            </table>
            <div class="BtnList">
            	<ul>
                  	<li><input type="button" class="btn_submit" title="등록" onclick="input_check();" /></li>
                </ul>
            </div>
		</form>
	</div>
<iframe name=if_nvl id=if_nvl src='' style='display:none'></iframe>
</body>
</html>
